﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace PriceCuttingWar
{
	public partial class HowToPlay : UserControl
	{
		public HowToPlay()
		{
			// Required to initialize variables
			InitializeComponent();
            GSystem.HowToPlay = this;
            BtnShowAgain.MouseLeftButtonDown += new MouseButtonEventHandler(BtnShowAgain_MouseLeftButtonDown);
            Btn_PlayNow.Click += new RoutedEventHandler(Btn_PlayNow_Click);
            ANI_Start.Completed += (s, e) =>
            {
                this.Visibility = System.Windows.Visibility.Collapsed;
            };
            UICard_Mony.FoodInfo = new ItemInfo() { Type = 1, Money = 100, Money2 = 80 };
            UICard_Cut.FoodInfo = new ItemInfo() { Type = 1, Money = 100, Money2 = 90 };
		}
        bool _isShowAgain = true;
        bool isShowAgain
        {
            get { return _isShowAgain; }
            set
            {
                if (_isShowAgain == value)
                    return;
                if (value)
                    Selected.Visibility = System.Windows.Visibility.Visible;
                else
                    Selected.Visibility = System.Windows.Visibility.Collapsed;
                
                _isShowAgain = value;
                IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings;
                if (storage.Contains("IsShowAgain"))
                    storage["IsShowAgain"] = value;
                else
                    storage.Add("IsShowAgain", value);
            }
        }
        void Btn_PlayNow_Click(object sender, RoutedEventArgs e)
        {
            Hide();
        }

        void BtnShowAgain_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            isShowAgain = !isShowAgain;
        }
        public void ShowMe()
        {
            this.Visibility = System.Windows.Visibility.Visible;
            ANI_Show.Begin();/*
            IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings;
            if (!storage.Contains("IsShowAgain"))
                Selected.Visibility = System.Windows.Visibility.Collapsed;
            else
            {
                bool b = (bool)storage["IsShowAgain"];
                if (!b)
                    Selected.Visibility = System.Windows.Visibility.Visible;
                else
                    Selected.Visibility = System.Windows.Visibility.Collapsed;
            }*/
        }
        public void Show()
        {
            
            IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings;
            if (!storage.Contains("IsShowAgain"))
            {
                isShowAgain = true;
            }
            else
            {
                bool b = (bool)storage["IsShowAgain"];
                if (!b)
                    return;                

            }
            ShowMe();
        }
        public void Hide()
        {
            ANI_Start.Begin();
        }
	}
}